﻿# 指定cmake版本
cmake_minimum_required(VERSION 3.15.0)

# 工程名称
project(ftmqtt_core)

# cmake的C++设置 已在toolchain_options.cmake设置了
#set(CMAKE_CXX_STANDARD 14)

# 添加预定义宏 
MESSAGE(INFO "--------------------------------")
# 是否打印输出
option(ENABLE_TRACE_PRINTF "option for trace" ON)
if (ENABLE_TRACE_PRINTF) 
	add_definitions(-DENABLE_TRACE_PRINTF)
endif(ENABLE_TRACE_PRINTF)
# 是否打印日志
option(ENABLE_LOG_PRINTF "option for log" ON)
if (ENABLE_LOG_PRINTF) 
	add_definitions(-DENABLE_LOG_PRINTF)
endif(ENABLE_LOG_PRINTF)

MESSAGE(STATUS "option for trace : ${ENABLE_TRACE_PRINTF}")
MESSAGE(STATUS "option for log : ${ENABLE_LOG_PRINTF}")
# 字符集使用unicode
#add_definitions(-DUNICODE -D_UNICODE)

# 移除警告信息
add_definitions(-w)
# 废弃警告
# SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fPIC)
# 启用pkg_check_modules加载依赖库
#include(FindPkgConfig)
#pkg_check_modules (GLIB REQUIRED IMPORTED_TARGET glib-2.0)
#pkg_check_modules (DBUS REQUIRED IMPORTED_TARGET dbus-1)
#pkg_check_modules (SQLITE3 REQUIRED IMPORTED_TARGET sqlite3)


# 遍历头文件
file(GLOB_RECURSE headerFiles "${PROJECT_SOURCE_DIR}/*.hpp" "${PROJECT_SOURCE_DIR}/*.h")
# 遍历源文件
file(GLOB_RECURSE srcFiles "${PROJECT_SOURCE_DIR}/*.cpp" "${PROJECT_SOURCE_DIR}/*.c")

# 输出遍历文件信息
MESSAGE(STATUS "Build headerFiles: ${headerFiles}")
MESSAGE(STATUS "Build srcFiles: ${srcFiles}")

add_library (${PROJECT_NAME}_static STATIC ${headerFiles} ${srcFiles})
#add_library (${PROJECT_NAME}_shared SHARED ${headerFiles} ${srcFiles})
IF(DEFINED TPROJECT_VERSION)
	MESSAGE(STATUS " TPROJECT_VERSION: ${TPROJECT_VERSION}")
	SET_TARGET_PROPERTIES (${PROJECT_NAME}_static PROPERTIES VERSION ${TPROJECT_VERSION} SOVERSION 1 )
ENDIF()

# 链接库文件
target_link_libraries(${PROJECT_NAME}_static PUBLIC  wolfmqtt wolfssl  pthread dl)
#target_link_libraries(${PROJECT_NAME}_shared PUBLIC  wolfmqtt wolfssl  pthread dl)
# 加载源文件
target_include_directories(${PROJECT_NAME}_static PUBLIC ${PROJECT_SOURCE_DIR})
#target_include_directories(${PROJECT_NAME}_shared PUBLIC ${PROJECT_SOURCE_DIR})

# 加载库依赖头
target_include_directories(${PROJECT_NAME}_static PUBLIC ${PROJECT_ROOT}/3rdparty/wolfMQTT)
#target_include_directories(${PROJECT_NAME}_shared PUBLIC ${PROJECT_ROOT}/3rdparty/wolfMQTT)

# 加载依赖库
#target_link_directories(${PROJECT_NAME}_static PUBLIC ${JSONCPP_LIBRARY_DIR} ${OPENSSL_LIBRARY_DIR} ${CURL_LIBRARY_DIR} ${PAHO_MQTTC_LIBRARY_DIR})	
#target_link_directories(${PROJECT_NAME}_shared PUBLIC ${JSONCPP_LIBRARY_DIR} ${OPENSSL_LIBRARY_DIR} ${CURL_LIBRARY_DIR} ${PAHO_MQTTC_LIBRARY_DIR})	
# 安装头文件
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    DESTINATION ${CMAKE_INSTALL_PREFIX}/include
    FILES_MATCHING
    PATTERN "*.h"
    PATTERN "*.hpp" 
	PATTERN "CMakeLists.txt" EXCLUDE
    )
	# 安装文件
INSTALL(TARGETS ${PROJECT_NAME}_static
    ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
    LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
    RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
# 安装文件
#INSTALL(TARGETS ${PROJECT_NAME}_shared
#    ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
#    LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
#    RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
# 安装配置文件
#install(FILES 
#${OPENSSL_LIBRARY_DIR}/libcrypto.a 
#${CURL_LIBRARY_DIR}/libcurl.a 
#${PAHO_MQTTC_LIBRARY_DIR}/libpaho-mqtt3cs.a 
#${OPENSSL_LIBRARY_DIR}/libssl.a 
#${JSONCPP_LIBRARY_DIR}/libjsoncpp.a 
#DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
#)



